package com.woniuxy.hotel.user.mapper;

import java.util.Collection;
import java.util.List;

import com.woniuxy.hotel.user.pojo.Customer;
import com.woniuxy.hotel.user.util.Page;

import org.apache.ibatis.annotations.*;

/**
 * @author Administrator
 *
 */
public interface CustomerMapper {
	int deleteByPrimaryKey(Integer id);

	int insert(Customer record);

	int insertSelective(Customer record);

	/**
	 * 通过id查询宾客信息（包含用户、会员信息）
	 *
	 * @param id
	 * @return
	 */
	Customer selectByPrimaryKey(Integer id);

	int updateByPrimaryKeySelective(Customer record);

	int updateByPrimaryKey(Customer record);

	/**
	 * 通过身份证查询宾客信息
	 *
	 * @param identity
	 * @return
	 */
	Customer findCustomerByIdentity(String identity);

	/**
	 * 查询所有宾客信息(包含会员与非会员)
	 *
	 * @return
	 */
	List<Customer> showAll();

	/**
	 * 查询所有会员信息
	 *
	 * @return
	 */
	Collection<Customer> showAllIsVip();

	/**
	 * 通过传入一个宾客对象（含name（可空）,identify（可空）,phone（可空）,vipId(可空),vip.level.id(可空)
	 * 查询符合条件的宾客信息
	 *
	 * @param customer
	 * @return
	 */
	List<Customer> findCustome(@Param("customer") Customer customer, @Param("page") Page<Customer> page);

	/**
	 *
	 * 通过会员编号vipId查询会员信息
	 * @param vipId
	 * @return
	 */
	Customer findCustomerByVipId(String vipId);

	Customer findLoginInfo(String account);

	/**
	 * @author ly
	 * @title: Reserve
	 * @projectName SSMSD
	 * @description: 根据宾客部分信息查询全部信息
	 * @date 2019年7月31日09:32:06
	 */
	@Select("<script>" + "select * from customer" + "<where>" + "<if test='name != null'>" + " and name like #{name}"
			+ "</if>" + "<if test='identify != null'>" + " and identify like #{identify}" + "</if>" + "</where>"
			+ "</script>")
	Customer findCustomer(Customer customer);

	@Select("select * from customer")
	List<Customer> findAllCustomer();

	@Insert("insert into customer(name,identify,createDate)VALUES(#{name},#{identify},#{createDate})")
	void addCustomer(Customer customer);

	/**
	 * 通过宾客编号查询宾客信息
	 */
	@Select("select * from customer where id=#{id}")
	@Results({
			@Result(id=true,column="id",property="id"),
			@Result(column="name",property="name"),
			@Result(column="identify",property="identify"),
			@Result(column="vid",property="vip",one=@One(
					select="com.woniuxy.hotel.user.mapper.VipMapper.findVipByVid"
			)),
	})
	Customer findCustomerInfo(Integer id);

	int getTotal(@Param("customer") Customer customer);


	@Select("select * from customer where uid = #{id}")
	Customer findCustomerByUserId(Integer id);

}